//
//  WNWalletVC.swift
//  WalkNovel
//
//  Created by Kevin on 2023/7/7.
//

import UIKit

class WNWalletVC: WNBaseVC {
        
    lazy var walletHeaderView: WalletHeaderView = {
        return WalletHeaderView(frame: .init(x: 0, y: 0, width: ScreenW, height: 186))
    }()
    
    lazy var walletTabView: WNTableView = {
        let tab = WNTableView()
        tab.register(SettingCell.self, forCellReuseIdentifier: SettingCell.identifier)
        tab.backgroundColor = .init(named: "white_F7F7F7")
        tab.delegate = self
        tab.dataSource = self
        tab.rowHeight = 60
        tab.isScrollEnabled = false
        tab.tableHeaderView = walletHeaderView
        return tab
    }()
        
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func viewConfig() {
        view.addSubview(walletTabView)
        walletTabView.snp.makeConstraints { make in
            make.top.equalTo(NaviTotalHeight)
            make.left.right.bottom.equalTo(0)
        }
    }
    
    override func dataConfig() {
        pageName = "My Wallet"
        navView.titleName = "My Wallet"
        let gold = "\(WNSingleData.shared.userGold)"
        walletHeaderView.goldCount.text = gold
        let w = wn_getTextW(textStr: gold, font: .wn_font(name: .bold, size: 40), height: 40)*0.5
        walletHeaderView.headerImage.snp.updateConstraints { make in
            make.centerX.equalToSuperview().offset(-8-w)
        }
        walletHeaderView.headerImage.wn_setupImg(getUser()?.avatar, placeHolder: "placeholder_header")
    }
}

extension WNWalletVC: UITableViewDelegate, UITableViewDataSource {
        
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 4
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: SettingCell.identifier, for: indexPath) as! SettingCell
        cell.walletType = indexPath.item
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        switch indexPath.item {
        case 0:
            navigationController?.pushViewController(WNTransVC(), animated: true)
        case 1:
            navigationController?.pushViewController(WNUnlockedVC(), animated: true)
        case 2:
            navigationController?.pushViewController(WNBonusVC(), animated: true)
//        case 3:
//            navigationController?.pushViewController(WNGiveVC(), animated: true)
        case 3:
            wn_pushStoreVC()
        default: break
        }
    }
}
